library(tidyverse)
library(academictwitteR)
library(lubridate)
library(corpus)
library(RColorBrewer)
library(viridisLite)
library(glue)

#set twitter API bearer token 
set_bearer()


#First round of Democratic tweets (Aug 2022)
#114
`114` <- get_all_tweets(
  users = c("SenDuckworth", "TammyDuckworth", "ChrisVanhollen", "vanhollenforMD", "RepKirkpatrick", "Ann_Kirkpatrick", "SenatorReid"),
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2017-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-2", 
  bind_tweets = FALSE)

`114` <- `114` %>%  bind_tweets(data_path = "tweetdata114-2", output_format = "tidy")

#114-115
`114-5` <- get_all_tweets(
  users = c("KyrstenSinema"),
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2019-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-5-2", 
  bind_tweets = FALSE)

`114-5` <- `114-5` %>%  bind_tweets(data_path = "tweetdata114-5-2", output_format = "tidy")

#114-116
`114-6` <- get_all_tweets(
  users = c("DCCCchair", "repmarciafudge", "mlfudge", "reprichmond", "cedricrichmond", ),
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-6", 
  bind_tweets = FALSE)

`114-6` <- `114-6` %>%  bind_tweets(data_path = "tweetdata114-6", output_format = "tidy")

#114-117, A-B
`114-7-AB` <- get_all_tweets(
  users = c("repadams", "almaforcongres", "RepPeteAguilar", "PeterAguilar", "SenatorBaldwin", "TammyBaldwin", 
            "RepKarenBass", "KarenBassLA", "RepBeatty", "JoyceBeatty", "SenatorBennet", "MichaelBennet", "RepBera", "BeraforCongress", 
            "RepDonBeyer", "DonBeyerVA", "SanfordBishop", "Bishop4Congress","repblumenauer", "SenBlumenthal", "DickBlumenthal", "RepBonamici", 
            "SenBooker", "CoryBooker", "CongBoyle", "RepBrendanBoyle", "SenSherrodBrown", "SherrodBrown", 
            "RepBrownley", "JuliaBrownley", "RepCheri", "CheriBustos", "GKButterfield"),
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-AB", 
  bind_tweets = FALSE)

`114-7-AB` <- `114-7-AB` %>%  bind_tweets(data_path = "tweetdata114-7-AB", output_format = "tidy")

#114-117, C
`114-7-C` <- get_all_tweets(
  users = c("SenatorCantwell", "RepCardenas", 
            "Tcardenas", "SenatorCardin", "BenCardinforMD", "SenatorCarper", "TomCarperforDE", "RepAndreCarson", "Andre4Congress",
            "RepCartwright", "CartwrightPA", "SenBobCasey", "Bob_Casey", "USRepKCastor", "KathyCastorFL", "JoaquinCastrotx", "Castro4Congress", 
            "RepJudyChu", "JudyChuCampaign", "RepCicilline", "davidcicilline",
            "RepKClark", "TeamKClark", "RepYvetteClarke", "VoteYvette", "repcleaver", "Vote4Cleaver", 
            "WhipClyburn", "ClyburnSC06", "RepCohen", "ReElectCohen", "GerryConnolly", "ElectConnolly","ChrisCoons", "ChrisCoonsforDE", "repjimcooper", 
            "CoopforCongress", "RepJimCosta", "RepJoeCourtney", "JoeCourtneyCT", "RepCuellar", "CuellarCampaign"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-C", 
  bind_tweets = FALSE)

`114-7-C` <- `114-7-C` %>%  bind_tweets(data_path = "tweetdata114-7-C", output_format = "tidy")

#114-117, D
`114-7-D` <- get_all_tweets(
  users = c("RepDannyDavis", "DannyKDavis7th", "RepPeterDeFazio",
            "DeFazio4Oregon", "RepDianaDeGette", "DeGette5280", "rosadelauro", "Rosa_DeLauro", "RepDelBene", "SuzanDelBene", "RepDeSaulnier", "MarkDeSaulnier", 
            "RepTedDeutch", "TedDeutch", "RepDebDingell","DebDingell", "RepLloydDoggett", "LloydDoggettTX", "USRepMikeDoyle", "SenatorDurbin", "DickDurbin"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-D", 
  bind_tweets = FALSE)

`114-7-D` <- `114-7-D` %>%  bind_tweets(data_path = "tweetdata114-7-D", output_format = "tidy")

#114-117, E-J
`114-7-EJ` <- get_all_tweets(
  users = c("RepAnnaEshoo", "Eshoo4Congress", "RepDwightEvans", "DwightEvansPA", "SenFeinstein", "SenFeinstein",
            "RepBillFoster", "Foster4Congress", "RepLoisFrankel", "LoisFrankel", "RepRubenGallego", "RubenGallego", "RepGaramendi", "JohnGaramendi", 
            "SenGillibrand", "gillibrandny", "RepAlGreen", "RepAlGreenTX","RepRaulGrijalva", "standwithraul", "MartinHeinrich", "TeamHeinrich", 
            "RepBrianHiggins", "Higgins4WNY", "jahimes", "maziehirono", "mazieforhawaii", "LeaderHoyer", "StenyHoyer", "RepHuffman",
            "JaredHuffman", "JacksonLeeTX18", "sjl4hrc", "RepJeffries", "HakeemJeffries", "RepEBJ", "RepHankJohnson", "ReElectHank"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-EJ", 
  bind_tweets = FALSE)

`114-7-EJ` <- `114-7-EJ` %>%  bind_tweets(data_path = "tweetdata114-7-EJ", output_format = "tidy")


#114-117, K-L
`114-7-KL` <- get_all_tweets(
  users = c("timkaine", "RepMarcyKaptur", "Marcy_Kaptur", "USRepKeating","WilliamKeating", "RepRobinKelly", "RobinLynneKelly", "RepDanKildee", "DanKildee", "RepDerekKilmer",
            "DerekKilmer", "RepRonKind", "KindforCongress", "SenAngusKing", "SenAmyKlobuchar", "amyklobuchar",
            "RepAnnieKuster", "AnnMcLaneKuster", "JimLangevin", "LangevinForRI", "RepRickLarsen", "larsenrick", "RepJohnLarson", "JohnLarsonCT", "RepLawrence", "BrendaLLawrence", 
            "SenatorLeahy", "RepBarbaraLee","BLeeForCongress", "RepTedLieu", "tedlieu", "RepZoeLofgren", "ZoeLofgren", "RepLowenthal", "alanlowenthal", "RepStephenLynch", "RepLynch"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-KL", 
  bind_tweets = FALSE)

`114-7-KL` <- `114-7-KL` %>%  bind_tweets(data_path = "tweetdata114-7-KL", output_format = "tidy")

#114-117, M
`114-7-M` <- get_all_tweets(
  users = c("RepMaloney", "CarolynBMaloney", "RepSeanMaloney",
            "Sen_JoeManchin", "SenMarkey", "EdMarkey", "DorisMatsui", "Matsui4Congress", "BettyMcCollum04", "VoteBetty", "RepMcGovern", "McGovernMA", "RepMcNerney", "jerrymcnerney",
            "RepGregoryMeeks","GregMeeksNYC", "SenatorMenendez", "BobMenendezNJ", "RepGraceMeng", "Grace4NY", "SenJeffMerkley", "JeffMerkley", "RepGwenMoore", "Gwen4Congress", 
            "teammoulton", "RepMoulton", "ChrisMurphyCT",
            "SenMurphyOffice", "PattyMurray", "MurrayCampaign"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-M", 
  bind_tweets = FALSE)

`114-7-M` <- `114-7-M` %>%  bind_tweets(data_path = "tweetdata114-7-M", output_format = "tidy")


#114-117, N-Q
`114-7-NQ` <- get_all_tweets(
  users = c( "RepJerryNadler", "JerryNadler", "gracenapolitano", "grace4congress", "RepRichardNeal", "NealForCongress", "DonaldNorcross", 
             "DonNorcross4NJ", "EleanorNorton","FrankPallone", "pallonefornj", "BillPascrell", "PascrellforNJ", "RepDonaldPayne", "DonaldPayneJr", 
             "SpeakerPelosi", "TeamPelosi", "RepPerlmutter", "Ed4Colorado", "SenGaryPeters", "GaryPeters",
             "RepScottPeters", "ScottPetersSD", "ScottPetersCA50", "chelliepingree", "PingreeforME", "StaceyPlaskett", "repmarkpocan", "MarkPocan", 
             "RepDavidEPrice", "RepMikeQuigley", "QuigleyCampaign"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-NQ", 
  bind_tweets = FALSE)

`114-7-NQ` <- `114-7-NQ` %>%  bind_tweets(data_path = "tweetdata114-7-NQ", output_format = "tidy")

#114-117, R-S
`114-7-RS` <- get_all_tweets(
  users = c("SenJackReed","jackreed2020", "RepKathleenRice", "KathleenRice","RepRoybalAllard", "RepRaulRuizMD", "Dr_RaulRuiz", 
            "Call_Me_Dutch", "RepBobbyRush", "bobbyrushfor1st", "RepTimRyan", "TimRyan", "Kilili_Sablan", "RepLindaSanchez", "LindaTSanchez","SenSanders", "BernieSanders", 
            "RepSarbanes", "JohnSarbanes", "repschakowsky", "janschakowsky", "SenBrianSchatz", "brianschatz", "RepAdamSchiff", "AdamSchiff", "RepSchrader", "SenSchumer",
            "chuckschumer", "repdavidscott", "BobbyScott", "BobbyScott4VA3", "RepTerriSewell", "Sewell4Congress", "SenatorShaheen", "JeanneShaheen", "BradSherman", "BradSherman4SFV"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-RS", 
  bind_tweets = FALSE)

`114-7-RS` <- `114-7-RS` %>%  bind_tweets(data_path = "tweetdata114-7-RS", output_format = "tidy")

#114-117, S-V
`114-7-SV` <- get_all_tweets(
  users = c("RepSires","AlbioSiresNJ", "RepAdamSmith", "electadamsmith", "RepSpeier", "JackieSpeier", "SenStabenow", "stabenow", "RepSwalwell", "ericswalwell", "RepMarkTakano",
            "RepMarkTakano", "SenatorTester", "jontester", "BennieGThompson", "BGThompsonMS", "RepThompson","Mike_CA05", "repdinatitus", "dinatitus", "RepPaulTonko", "PaulTonko", 
            "NormaJTorres", "Norma4COngress", "RepJuanVargas", "JuanVargas4CA", "RepVeasey", "MarcVeasey", "RepFilemonVela",
            "FilemonVela", "NydiaVelazquez", "ReElectNydia"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-SV", 
  bind_tweets = FALSE)

`114-7-SV` <- `114-7-SV` %>%  bind_tweets(data_path = "tweetdata114-7-SV", output_format = "tidy")

#114-117, W-Y
`114-7-WY` <- get_all_tweets(
  users = c("MarkWarner", "MarkWarnerVA", "SenWarren", "ewarren", "RepDWStweets", "DWStweets", "RepMaxineWaters", "MaxineWaters",
            "RepBonnie","Bonnie4Congress", "PeterWelch", "WelchforVT", "SenWhitehouse", "SheldonforRI", "RepWilson", "WydenPress", "RonWyden", "WydenPress", "RepJohnYarmuth"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-WY", 
  bind_tweets = FALSE)

`114-7-WY` <- `114-7-WY` %>%  bind_tweets(data_path = "tweetdata114-7-WY", output_format = "tidy")

#115 
`115` <- get_all_tweets(
  users = c("RosenforNevada"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2019-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115", 
  bind_tweets = FALSE)

`115` <- `115` %>%  bind_tweets(data_path = "tweetdata115", output_format = "tidy")

#115-6
`115-6` <- get_all_tweets(
  users = c("KamalaHarris"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-6", 
  bind_tweets = FALSE)

`115-6` <- `115` %>%  bind_tweets(data_path = "tweetdata115-6", output_format = "tidy")


#115-7, B-H
`115-7-BH` <- get_all_tweets(
  users = c("RepBarragan", "Nanette4CA", "RepLBR", "LisaBRochester", "RepAnthonyBrown", "BrownforMD", "RepCarbajal", "carbajalsalud", "RepLouCorrea", "voteloucorrea", "SenCortezMasto", 
            "CortezMasto", "RepCharlieCrist", "CharlieCrist", "RepValDemings", "valdemings","SenDuckworth", "TammyDuckworth", "RepEspaillat", "EspaillatNY", "RepJimmyGomez", "JimmyGomezCA",
            "RepGonzalez", "VoteVicente", "RepJoshG", "JoshGottheimer", "SenatorHassan", "Maggie_Hassan"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-7-BH", 
  bind_tweets = FALSE)

`115-7-BH` <- `115-7-BH` %>%  bind_tweets(data_path = "tweetdata115-7-BH", output_format = "tidy")

#115-7, J-W
`115-7-JW` <- get_all_tweets(
  users = c("RepJayapal", "PramilaJayapal", "RepRoKhanna", "RoKhanna", "CongressmanRaja", "RajaforCongress", "RepConorLamb", "ConorLambPA", "RepAlLawsonJr", "AlLawsonJr", "RepMcEachin", "Donald_McEachin",
            "RepJoeMorelle", "votemorelle", "RepStephMurphy", "MurphyforFL", "RepOHalleran", "TomOhalleran", "RepJimmyPanetta", "JImmyPanetta", "RepRaskin", "jamie_raskin", "RepMGS", "marygayscanlon",
            "RepSchneider", "Schneider4IL10", "SenTinaSmith", "TinaSmithMN", "RepDarrenSoto", "DarrenSoto", "RepTomSuozzi", "Tom_Suozzi", "ChrisVanHollen", "RepSusanWild", "wildforcongress"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-7-JW", 
  bind_tweets = FALSE)

`115-7-JW` <- `115-7-JW` %>%  bind_tweets(data_path = "tweetdata115-7-JW", output_format = "tidy")

#116
`116` <- get_all_tweets(
  users = c("RepDebHaaland", "DebHaalandNM"), 
  start_tweets = "2019-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116", 
  bind_tweets = FALSE)

`116` <- `116` %>%  bind_tweets(data_path = "tweetdata116", output_format = "tidy")


#116-7, A-L
`116-7-AL` <- get_all_tweets(
  users = c("RepColinAllred", "ColinAllredTX", "RepCindyAxne", "Axne4Congress", "RepEdCase", "EdCaseHawaii", "RepCasten", "SeanCasten", "RepAngieCraig", "AngieCraigMN", "RepJasonCrow", "JasonCrowCO",
            "RepDavids", "sharicedavids", "RepDean", "MadeleineDean","RepEscobar", "vgescobar", "RepFletcher", "Lizzie4Congress", "RepChuyGarcia", "ChuyforCongress", "RepSylviaGarcia",
            "LaCongresista", "RepGolden", "golden4congress", "RepJoshHarder", "JoshHarder",
            "RepJahanaHayes", "JahanaHayesCT", "RepHorsford", "StevenHorsford", "RepHoulahan", "HoulahanForPa", "SenMarkKelly", "CaptMarkKelly", "RepAndyKimNJ", "AndyKimNJ", "RepKirkpatrick", "Ann_Kirkpatrick",
            "RepSusieLee", "SusieLeeNV", "RepAndyLevin", "Andy_Levin", "RepMikeLevin", "MikeLevin", "RepElaineLuria", "ElaineLuriaVA"), 
  start_tweets = "2019-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-AL", 
  bind_tweets = FALSE)

`116-7-AL` <- `116-7-AL` %>%  bind_tweets(data_path = "tweetdata116-7-AL", output_format = "tidy")

#116-7, D
`116-7-D` <- get_all_tweets(
  users = c("repdelgado", "DelgadoforNY"), 
  start_tweets = "2019-01-03T00:00:00Z",
  end_tweets = "2022-05-22T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-D", 
  bind_tweets = FALSE)

`116-7-D` <- `116-7-D` %>%  bind_tweets(data_path = "tweetdata116-7-D", output_format = "tidy")


#116-7, M-W
`116-7-MW` <- get_all_tweets(
  users = c("RepMalinowski", "Malinowski", "RepLucyMcBath", "lucymcbath", "RepKweisiMfume", "Mfume4Congress", "RepJoeNeguse", "JoeNeguse",
            "RepAOC", "AOC", "Ilhan", "IlhanMN", "RepChrisPappas", "ChrisPappasNH", "RepDeanPhillips", "deanbphillips","RepKatiePorter", "katieporteroc", 
            "RepPressley", "AyannaPressley", "SenJackyRosen", "RosenforNevada", "GuamCongressman", "RepKimSchrier", "DrKimSchrier", "RepSherrill", "MikieSherrill", "SenatorSinema",
            "KyrstenSinema", "RepSlotkin", "ElissaSlotkin", "RepSpanberger", "SpanbergerVA07", "RepGregStanton", "gregstantonaz", "RepHaleyStevens", "HaleyLive", "RepRashida", "rashidatlaib", 
            "RepLoriTrahan","LoriTrahanMA", "RepDavidTrone", "davidjtrone", "RepUnderwood", "LaurenUnderwood", "RepWexton", "JenniferWexton"), 
  start_tweets = "2019-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-MW", 
  bind_tweets = FALSE)

`116-7-MW` <- `116-7-MW` %>%  bind_tweets(data_path = "tweetdata116-7-MW", output_format = "tidy")

#117, A-R
`117-AR` <- get_all_tweets(
  users = c( "RepAuchincloss", "JakeAuch", "RepBourdeaux", "Carolyn4GA7", "RepBowman",
             "JamaalBowmanNY", "RepShontelBrown", "ShontelMBrown", "RepCori", "CoriBush", "RepTroyCarter", "CongresswomanSC", "Sheila4Congress",
             "SenatorHick", "Hickenlooper", "RepSaraJacobs", "SaraJacobsCA","RepMondaire", "MondaireJones", "KaheleRep", "KaiKahele", "RepTeresaLF", "TeresaForNM", 
             "SenatorLujan", "benraylujan", "RepKManning", "KathyManningNC", "RepMrvan", "Fjmrvan",
             "mrvan4congress", "RepMarieNewman", "Marie4Congress", "SenOssof", "ossoff", "TeamOssof", "SenAlexPadilla", "AlexPadilla4CA", "RepDeborahRoss", 
             "DeborahRossNC"), 
  start_tweets = "2021-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-AR2", 
  bind_tweets = FALSE)

`117-AR` <- `117-AR` %>%  bind_tweets(data_path = "tweetdata116-7-AR2", output_format = "tidy")

#117, S-W
`117-SW` <- get_all_tweets(
  users = c( "Rep_Stansbury", "MelanieforNM", "RepStricklandWA", "StricklandforWA", "RepRitchie",
             "RitchieTorres", "SenatorWarnock", "ReverendWarnock", "RepNikema", "NikemaWilliams"), 
  start_tweets = "2021-01-03T00:00:00Z",
  end_tweets = "2022-08-17T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata117-SW2", 
  bind_tweets = FALSE)

`117-SW` <- `117-SW` %>%  bind_tweets(data_path = "tweetdata117-SW2", output_format = "tidy")

#Biden
Biden <- get_all_tweets(
  users = c("JoeBiden", "POTUS"),
  start_tweets = "2021-01-03T00:00:00Z",
  end_tweets = "2022-07-14T00:00:00Z",
  n = 100000, 
  data_path = "BPrestweetdata", 
  bind_tweets = FALSE)


Biden <- Biden %>%  bind_tweets(data_path = "BPrestweetdata", output_format = "tidy")


#114, A-T
`114-AT` <- get_all_tweets(
  users = c("RepBradAshford", "SenatorBoxer", "BarbaraBoxer", "RepLoisCapps", "JohnCarneyDE", "johncarneyforde", 
            "DonnaFEdwards", "chakafattah", "GwenGraham", "AlanGrayson", "SupJaniceHahn", "JaniceHahn","USRepRHinojosa", 
            "RepMikeHonda", "RepSteveIsrael",
            "SenatorBarb", "PatrickMurphyFL", "charlesbrangel","cbrangel", "LorettaSanchez", "RepMarkTakai","MarkTakai"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2017-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-AT", 
  bind_tweets = FALSE)

`114-AT` <- `114-AT` %>%  bind_tweets(data_path = "tweetdata114-AT", output_format = "tidy")

#114-115, B-W
`114-5-BW` <- get_all_tweets(
  users = c("BobBradyPHL", "XavierBecerra", "mikecapuano", "RepJohnConyers", "JoeCrowleyNY", "JohnDelaney", "JoeforIndiana", 
            "keithellison", "EllisonCmpaign", "Elizabeth_Esty", "ElizabethEstyCT", "SenFranken","alfranken", "RepGutierrez", "RepHanabusa",
            "ColleenHanabusa", "SenatorHeitkamp", "HeidiHeitkamp","repsandylevin", "Levin4Congress", "RepLujanGrisham","Michelle4NM", "McCaskillOffice",
            "clairecmc","McCaskill4MO", "SenBillNelson", "RepBetoORourke","BetoORourke", "RepJaredPolis", "jaredpolis",
            "PolisForCO", "louiseslaughter", "VoteLouiseNY","RepTimWalz", "Tim_Walz"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2019-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-5-BW", 
  bind_tweets = FALSE)

`114-5-BW` <- `114-5-BW` %>%  bind_tweets(data_path = "tweetdata114-5-BW", output_format = "tidy")

#114-116, C-V
`114-6-CV` <- get_all_tweets(
  users = c("RepCummings", "ReElectCummings", "LacyClayMO1", "RepEliotEngel", "TulsiPress", "TulsiGabbard", "LtGovDennyHeck", 
            "DennyHeck", "joekennedy", "repjohnlewis", "RepLipinski", "DanLipinski","daveloebsack", "NitaLowey", "collinpeterson",
            "RepJoseSerrano", "SenatorTomUdall", "tomudall","USAmbNZ", "RepVisclosky"), 
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-6-CV", 
  bind_tweets = FALSE)

`114-6-CV` <- `114-6-CV` %>%  bind_tweets(data_path = "tweetdata114-6-CV", output_format = "tidy")

#115,  K-S
`115-KS` <- get_all_tweets(
  users = c("RepKihuen", "RubenKihuen", "VoteBrendaJones", "RepSheaPorter", "TeamSheaPorter"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2019-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-KS", 
  bind_tweets = FALSE)

`115-KS` <- `115-KS` %>%  bind_tweets(data_path = "tweetdata115-KS", output_format = "tidy")

#115-116, J
`115-6-J` <- get_all_tweets(
  users = c("SenDougJones", "DougJones", "DougJonesHQ"), 
  start_tweets = "2017-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-6-J", 
  bind_tweets = FALSE)

`115-6-J` <- `115-6-J` %>%  bind_tweets(data_path = "tweetdata115-6-J", output_format = "tidy")

#116, B-T
`116-BT` <- get_all_tweets(
  users = c("RepBrindisi", "RepGilCisneros", "RepTjCox", "TJCoxCongress", "RepCunningham", "JoeCunninghamSC", 
            "kwanzahall", "RepKatieHill", "KatieHill4CA", "VoteKendraOK", "HornForCongress", "BenMcAdams","BenMcAdamsUT", "RepDMP", "DebbieforFL",
            "RepMaxRose", "MaxRose4NY", "RepHarley","HarleyRouda", "DonnaShalala", "RepTorresSmall","xochnm"), 
  start_tweets = "2019-01-03T00:00:00Z",
  end_tweets = "2021-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-BT", 
  bind_tweets = FALSE)

`116-BT` <- `116-BT` %>%  bind_tweets(data_path = "tweetdata116-BT", output_format = "tidy")


#117 Rescue
Democrat_tweets_117 <- Democrat_tweets %>%
  filter(user_username != "RepAuchincloss" & user_username != "JakeAuch" & user_username !="JakeAuch"& user_username !="RepBourdeaux" & user_username !="Carolyn4GA7" & user_username !="RepBowman"& 
           user_username !="JamaalBowmanNY"& user_username != "RepShontelBrown"& user_username !="ShontelMBrown" & user_username != "RepCori"& user_username !="CoriBush"& user_username !="RepTroyCarter"& user_username !="CongresswomanSC" & user_username !="Sheila4Congress"&
           user_username !="SenatorHick"& user_username !="Hickenlooper" & user_username !="RepSaraJacobs" & user_username !="SaraJacobsCA" & user_username !="RepMondaire"& user_username !="MondaireJones"& user_username !="KaheleRep"& user_username !="KaiKahele"& user_username !="RepTeresaLF" & user_username !="TeresaForNM"& 
           user_username !="SenatorLujan" & user_username !="benraylujan" & user_username !="RepKManning"& user_username !="KathyManningNC"& user_username !="RepMrvan"& user_username !="Fjmrvan"&
           user_username !="mrvan4congress" & user_username !="RepMarieNewman" & user_username !="Marie4Congress"& user_username != "SenOssof"& user_username !="ossoff"& user_username !="TeamOssof"& user_username !="SenAlexPadilla"& user_username !="AlexPadilla4CA"& user_username !="RepDeborahRoss"& 
           user_username !="DeborahRossNC" & user_username !="Rep_Stansbury"&  user_username !="MelanieforNM"& user_username !="RepStricklandWA"& user_username !="StricklandforWA"& user_username !="RepRitchie"&
           user_username !="RitchieTorres"& user_username !="SenatorWarnock"& user_username !="ReverendWarnock" & user_username !="RepNikema"& user_username !="NikemaWilliams")
View(Democrat_tweets_117)

#Bind together 
Democrat_tweets <- rbind(`114`, `114-5`, `114-6`, `114-7-AB`, `114-7-C`, `114-7-D`, `114-7-EJ`, `114-7-KL`, `114-7-M`, 
                         `114-7-NQ`, `114-7-RS`, `114-7-SV`, `114-7-WY`, `115`, `115-6`, `115-7-BH`, `115-7-JW`, 
                         `116`, `116-7-AL`, `116-7-D`, `116-7-MW`, `117-AR`, `117-SW`, Biden, Biden_VP)
View(Democrat_tweets)










#Second round of Democratic tweets (Jan 2023)

#114-7, A-B
`114-7-AB` <- get_all_tweets(
  users = c("repadams", "almaforcongres", "RepPeteAguilar", "PeterAguilar", "SenatorBaldwin", "TammyBaldwin", 
            "RepKarenBass", "KarenBassLA", "RepBeatty", "JoyceBeatty", "SenatorBennet", "MichaelBennet", "RepBera", "BeraforCongress", 
            "RepDonBeyer", "DonBeyerVA", "SanfordBishop", "Bishop4Congress","repblumenauer", "SenBlumenthal", "DickBlumenthal", "RepBonamici", 
            "SenBooker", "CoryBooker", "CongBoyle", "RepBrendanBoyle", "SenSherrodBrown", "SherrodBrown", 
            "RepBrownley", "JuliaBrownley", "RepCheri", "CheriBustos", "GKButterfield"),
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-AB-2", 
  bind_tweets = FALSE)

`114-7-AB` <- `114-7-AB` %>%  bind_tweets(data_path = "tweetdata114-7-AB-2", output_format = "tidy")

#114-117, C
`114-7-C` <- get_all_tweets(
  users = c("SenatorCantwell", "RepCardenas", 
            "Tcardenas", "SenatorCardin", "BenCardinforMD", "SenatorCarper", "TomCarperforDE", "RepAndreCarson", "Andre4Congress",
            "RepCartwright", "CartwrightPA", "SenBobCasey", "Bob_Casey", "USRepKCastor", "KathyCastorFL", "JoaquinCastrotx", "Castro4Congress", 
            "RepJudyChu", "JudyChuCampaign", "RepCicilline", "davidcicilline",
            "RepKClark", "TeamKClark", "RepYvetteClarke", "VoteYvette", "repcleaver", "Vote4Cleaver", 
            "WhipClyburn", "ClyburnSC06", "RepCohen", "ReElectCohen", "GerryConnolly", "ElectConnolly","ChrisCoons", "ChrisCoonsforDE", "repjimcooper", 
            "CoopforCongress", "RepJimCosta", "RepJoeCourtney", "JoeCourtneyCT", "RepCuellar", "CuellarCampaign"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-C-2", 
  bind_tweets = FALSE)

`114-7-C` <- `114-7-C` %>%  bind_tweets(data_path = "tweetdata114-7-C-2", output_format = "tidy")

#114-117, D
`114-7-D` <- get_all_tweets(
  users = c("RepDannyDavis", "DannyKDavis7th", "RepPeterDeFazio",
            "DeFazio4Oregon", "RepDianaDeGette", "DeGette5280", "rosadelauro", "Rosa_DeLauro", "RepDelBene", "SuzanDelBene", "RepDeSaulnier", "MarkDeSaulnier", 
            "RepTedDeutch", "TedDeutch", "RepDebDingell","DebDingell", "RepLloydDoggett", "LloydDoggettTX", "USRepMikeDoyle", "SenatorDurbin", "DickDurbin"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-D-2", 
  bind_tweets = FALSE)

`114-7-D` <- `114-7-D` %>%  bind_tweets(data_path = "tweetdata114-7-D-2", output_format = "tidy")

#114-117, E-J
`114-7-EJ` <- get_all_tweets(
  users = c("RepAnnaEshoo", "Eshoo4Congress", "RepDwightEvans", "DwightEvansPA", "SenFeinstein", "SenFeinstein",
            "RepBillFoster", "Foster4Congress", "RepLoisFrankel", "LoisFrankel", "RepRubenGallego", "RubenGallego", "RepGaramendi", "JohnGaramendi", 
            "SenGillibrand", "gillibrandny", "RepAlGreen", "RepAlGreenTX","RepRaulGrijalva", "standwithraul", "MartinHeinrich", "TeamHeinrich", 
            "RepBrianHiggins", "Higgins4WNY", "jahimes", "maziehirono", "mazieforhawaii", "LeaderHoyer", "StenyHoyer", "RepHuffman",
            "JaredHuffman", "JacksonLeeTX18", "sjl4hrc", "RepJeffries", "HakeemJeffries", "RepEBJ", "RepHankJohnson", "ReElectHank"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-EJ-2", 
  bind_tweets = FALSE)

`114-7-EJ` <- `114-7-EJ` %>%  bind_tweets(data_path = "tweetdata114-7-EJ-2", output_format = "tidy")


#114-117, K-L
`114-7-KL` <- get_all_tweets(
  users = c("timkaine", "RepMarcyKaptur", "Marcy_Kaptur", "USRepKeating","WilliamKeating", "RepRobinKelly", "RobinLynneKelly", "RepDanKildee", "DanKildee", "RepDerekKilmer",
            "DerekKilmer", "RepRonKind", "KindforCongress", "SenAngusKing", "SenAmyKlobuchar", "amyklobuchar",
            "RepAnnieKuster", "AnnMcLaneKuster", "JimLangevin", "LangevinForRI", "RepRickLarsen", "larsenrick", "RepJohnLarson", "JohnLarsonCT", "RepLawrence", "BrendaLLawrence", 
            "SenatorLeahy", "RepBarbaraLee","BLeeForCongress", "RepTedLieu", "tedlieu", "RepZoeLofgren", "ZoeLofgren", "RepLowenthal", "alanlowenthal", "RepStephenLynch", "RepLynch"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-KL-2", 
  bind_tweets = FALSE)

`114-7-KL` <- `114-7-KL` %>%  bind_tweets(data_path = "tweetdata114-7-KL-2", output_format = "tidy")

#114-117, M
`114-7-M` <- get_all_tweets(
  users = c("RepMaloney", "CarolynBMaloney", "RepSeanMaloney",
            "Sen_JoeManchin", "SenMarkey", "EdMarkey", "DorisMatsui", "Matsui4Congress", "BettyMcCollum04", "VoteBetty", "RepMcGovern", "McGovernMA", "RepMcNerney", "jerrymcnerney",
            "RepGregoryMeeks","GregMeeksNYC", "SenatorMenendez", "BobMenendezNJ", "RepGraceMeng", "Grace4NY", "SenJeffMerkley", "JeffMerkley", "RepGwenMoore", "Gwen4Congress", 
            "teammoulton", "RepMoulton", "ChrisMurphyCT",
            "SenMurphyOffice", "PattyMurray", "MurrayCampaign"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-M-2", 
  bind_tweets = FALSE)

`114-7-M` <- `114-7-M` %>%  bind_tweets(data_path = "tweetdata114-7-M-2", output_format = "tidy")


#114-117, N-Q
`114-7-NQ` <- get_all_tweets(
  users = c( "RepJerryNadler", "JerryNadler", "gracenapolitano", "grace4congress", "RepRichardNeal", "NealForCongress", "DonaldNorcross", 
             "DonNorcross4NJ", "EleanorNorton","FrankPallone", "pallonefornj", "BillPascrell", "PascrellforNJ", "RepDonaldPayne", "DonaldPayneJr", 
             "SpeakerPelosi", "TeamPelosi", "RepPerlmutter", "Ed4Colorado", "SenGaryPeters", "GaryPeters",
             "RepScottPeters", "ScottPetersSD", "ScottPetersCA50", "chelliepingree", "PingreeforME", "StaceyPlaskett", "repmarkpocan", "MarkPocan", 
             "RepDavidEPrice", "RepMikeQuigley", "QuigleyCampaign"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-NQ-2", 
  bind_tweets = FALSE)

`114-7-NQ` <- `114-7-NQ` %>%  bind_tweets(data_path = "tweetdata114-7-NQ-2", output_format = "tidy")

#114-117, R-S
`114-7-RS` <- get_all_tweets(
  users = c("SenJackReed","jackreed2020", "RepKathleenRice", "KathleenRice","RepRoybalAllard", "RepRaulRuizMD", "Dr_RaulRuiz", 
            "Call_Me_Dutch", "RepBobbyRush", "bobbyrushfor1st", "RepTimRyan", "TimRyan", "Kilili_Sablan", "RepLindaSanchez", "LindaTSanchez","SenSanders", "BernieSanders", 
            "RepSarbanes", "JohnSarbanes", "repschakowsky", "janschakowsky", "SenBrianSchatz", "brianschatz", "RepAdamSchiff", "AdamSchiff", "RepSchrader", "SenSchumer",
            "chuckschumer", "repdavidscott", "BobbyScott", "BobbyScott4VA3", "RepTerriSewell", "Sewell4Congress", "SenatorShaheen", "JeanneShaheen", "BradSherman", "BradSherman4SFV"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-RS-2", 
  bind_tweets = FALSE)

`114-7-RS` <- `114-7-RS` %>%  bind_tweets(data_path = "tweetdata114-7-RS-2", output_format = "tidy")

#114-117, S-V
`114-7-SV` <- get_all_tweets(
  users = c("RepSires","AlbioSiresNJ", "RepAdamSmith", "electadamsmith", "RepSpeier", "JackieSpeier", "SenStabenow", "stabenow", "RepSwalwell", "ericswalwell", "RepMarkTakano",
            "RepMarkTakano", "SenatorTester", "jontester", "BennieGThompson", "BGThompsonMS", "RepThompson","Mike_CA05", "repdinatitus", "dinatitus", "RepPaulTonko", "PaulTonko", 
            "NormaJTorres", "Norma4COngress", "RepJuanVargas", "JuanVargas4CA", "RepVeasey", "MarcVeasey", "RepFilemonVela",
            "FilemonVela", "NydiaVelazquez", "ReElectNydia"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-SV-2", 
  bind_tweets = FALSE)

`114-7-SV` <- `114-7-SV` %>%  bind_tweets(data_path = "tweetdata114-7-SV-2", output_format = "tidy")

#114-117, W-Y
`114-7-WY` <- get_all_tweets(
  users = c("MarkWarner", "MarkWarnerVA", "SenWarren", "ewarren", "RepDWStweets", "DWStweets", "RepMaxineWaters", "MaxineWaters",
            "RepBonnie","Bonnie4Congress", "PeterWelch", "WelchforVT", "SenWhitehouse", "SheldonforRI", "RepWilson", "WydenPress", "RonWyden", "WydenPress", "RepJohnYarmuth"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata114-7-WY-2", 
  bind_tweets = FALSE)

`114-7-WY` <- `114-7-WY` %>%  bind_tweets(data_path = "tweetdata114-7-WY-2", output_format = "tidy")

#115-7, B-H
`115-7-BH` <- get_all_tweets(
  users = c("RepBarragan", "Nanette4CA", "RepLBR", "LisaBRochester", "RepAnthonyBrown", "BrownforMD", "RepCarbajal", "carbajalsalud", "RepLouCorrea", "voteloucorrea", "SenCortezMasto", 
            "CortezMasto", "RepCharlieCrist", "CharlieCrist", "RepValDemings", "valdemings","SenDuckworth", "TammyDuckworth", "RepEspaillat", "EspaillatNY", "RepJimmyGomez", "JimmyGomezCA",
            "RepGonzalez", "VoteVicente", "RepJoshG", "JoshGottheimer", "SenatorHassan", "Maggie_Hassan"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-7-BH-2", 
  bind_tweets = FALSE)

`115-7-BH` <- `115-7-BH` %>%  bind_tweets(data_path = "tweetdata115-7-BH-2", output_format = "tidy")

#115-7, J-W
`115-7-JW` <- get_all_tweets(
  users = c("RepJayapal", "PramilaJayapal", "RepRoKhanna", "RoKhanna", "CongressmanRaja", "RajaforCongress", "RepConorLamb", "ConorLambPA", "RepAlLawsonJr", "AlLawsonJr", "RepMcEachin", "Donald_McEachin",
            "RepJoeMorelle", "votemorelle", "RepStephMurphy", "MurphyforFL", "RepOHalleran", "TomOhalleran", "RepJimmyPanetta", "JImmyPanetta", "RepRaskin", "jamie_raskin", "RepMGS", "marygayscanlon",
            "RepSchneider", "Schneider4IL10", "SenTinaSmith", "TinaSmithMN", "RepDarrenSoto", "DarrenSoto", "RepTomSuozzi", "Tom_Suozzi", "ChrisVanHollen", "RepSusanWild", "wildforcongress"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata115-7-JW-2", 
  bind_tweets = FALSE)

`115-7-JW` <- `115-7-JW` %>%  bind_tweets(data_path = "tweetdata115-7-JW-2", output_format = "tidy")

#116-7, A-L
`116-7-AL` <- get_all_tweets(
  users = c("RepColinAllred", "ColinAllredTX", "RepCindyAxne", "Axne4Congress", "RepEdCase", "EdCaseHawaii", "RepCasten", "SeanCasten", "RepAngieCraig", "AngieCraigMN", "RepJasonCrow", "JasonCrowCO",
            "RepDavids", "sharicedavids", "RepDean", "MadeleineDean","RepEscobar", "vgescobar", "RepFletcher", "Lizzie4Congress", "RepChuyGarcia", "ChuyforCongress", "RepSylviaGarcia",
            "LaCongresista", "RepGolden", "golden4congress", "RepJoshHarder", "JoshHarder",
            "RepJahanaHayes", "JahanaHayesCT", "RepHorsford", "StevenHorsford", "RepHoulahan", "HoulahanForPa", "SenMarkKelly", "CaptMarkKelly", "RepAndyKimNJ", "AndyKimNJ", "RepKirkpatrick", "Ann_Kirkpatrick",
            "RepSusieLee", "SusieLeeNV", "RepAndyLevin", "Andy_Levin", "RepMikeLevin", "MikeLevin", "RepElaineLuria", "ElaineLuriaVA"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-AL-2", 
  bind_tweets = FALSE)

`116-7-AL` <- `116-7-AL` %>%  bind_tweets(data_path = "tweetdata116-7-AL-2", output_format = "tidy")

#116-7, M-W
`116-7-MW` <- get_all_tweets(
  users = c("RepMalinowski", "Malinowski", "RepLucyMcBath", "lucymcbath", "RepKweisiMfume", "Mfume4Congress", "RepJoeNeguse", "JoeNeguse",
            "RepAOC", "AOC", "Ilhan", "IlhanMN", "RepChrisPappas", "ChrisPappasNH", "RepDeanPhillips", "deanbphillips","RepKatiePorter", "katieporteroc", 
            "RepPressley", "AyannaPressley", "SenJackyRosen", "RosenforNevada", "GuamCongressman", "RepKimSchrier", "DrKimSchrier", "RepSherrill", "MikieSherrill", "SenatorSinema",
            "KyrstenSinema", "RepSlotkin", "ElissaSlotkin", "RepSpanberger", "SpanbergerVA07", "RepGregStanton", "gregstantonaz", "RepHaleyStevens", "HaleyLive", "RepRashida", "rashidatlaib", 
            "RepLoriTrahan","LoriTrahanMA", "RepDavidTrone", "davidjtrone", "RepUnderwood", "LaurenUnderwood", "RepWexton", "JenniferWexton"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-MW-2", 
  bind_tweets = FALSE)

`116-7-MW` <- `116-7-MW` %>%  bind_tweets(data_path = "tweetdata116-7-MW-2", output_format = "tidy")

#117, A-R
`117-AR` <- get_all_tweets(
  users = c( "RepAuchincloss", "JakeAuch", "RepBourdeaux", "Carolyn4GA7", "RepBowman",
             "JamaalBowmanNY", "RepShontelBrown", "ShontelMBrown", "RepCori", "CoriBush", "RepTroyCarter", "CongresswomanSC", "Sheila4Congress",
             "SenatorHick", "Hickenlooper", "RepSaraJacobs", "SaraJacobsCA","RepMondaire", "MondaireJones", "KaheleRep", "KaiKahele", "RepTeresaLF", "TeresaForNM", 
             "SenatorLujan", "benraylujan", "RepKManning", "KathyManningNC", "RepMrvan", "Fjmrvan",
             "mrvan4congress", "RepMarieNewman", "Marie4Congress", "SenOssof", "ossoff", "TeamOssof", "SenAlexPadilla", "AlexPadilla4CA", "RepDeborahRoss", 
             "DeborahRossNC"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata116-7-AR-2", 
  bind_tweets = FALSE)

`117-AR` <- `117-AR` %>%  bind_tweets(data_path = "tweetdata116-7-AR-2", output_format = "tidy")

#117, S-W
`117-SW` <- get_all_tweets(
  users = c( "Rep_Stansbury", "MelanieforNM", "RepStricklandWA", "StricklandforWA", "RepRitchie",
             "RitchieTorres", "SenatorWarnock", "ReverendWarnock", "RepNikema", "NikemaWilliams"), 
  start_tweets = "2022-08-17T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = Inf, 
  data_path = "tweetdata117-SW-2", 
  bind_tweets = FALSE)

`117-SW` <- `117-SW` %>%  bind_tweets(data_path = "tweetdata117-SW-2", output_format = "tidy")

#Biden
Biden <- get_all_tweets(
  users = c("JoeBiden", "POTUS"),
  start_tweets = "2021-01-20T00:00:00Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = 100000, 
  data_path = "BPrestweetdata-22", 
  bind_tweets = FALSE)


Biden <- Biden %>%  bind_tweets(data_path = "BPrestweetdata-22", output_format = "tidy")



#Bind together all 
Dems_2023 <- rbind(`114-7-AB`, `114-7-C`, `114-7-D`, `114-7-EJ`, `114-7-KL`, `114-7-M`, `114-7-NQ`, `114-7-RS`, `114-7-SV`, `114-7-WY`, 
                   `115-7-BH`, `115-7-JW`, `116-7-AL`, `116-7-MW`, `117-AR`, `117-SW`, Biden)

#Dates 
date_updated <- str_sub(Dems_2023$created_at, 1, 10)
date_updated

Dems_2023$created_at <- paste0(date_updated)

Dems_2023$created_at <- ymd(Dems_2023$created_at)

Democrats_congress <- Dems_2023 %>% 
  mutate(congress = case_when(
    created_at >= ymd('2021-01-03') & 
      created_at <= ymd('2023-01-02') ~ "117"))

#Democratic caucus membership/district info 
official_handle <- read_excel("Yale/Amelia work/Uncleaned data/official_handle.xlsx")
cdi_2010_2 <- read_excel("Yale/Amelia work/Uncleaned data/cdi_2010_2.xlsx")

Dem_caucus <- pivot_longer(official_handle, 
                           cols = c(official_twitter, personal_twitter, third_twitter), 
                           names_to = "twitter_type", values_to = "twitter_handle")

Dem_caucus2 <- Dem_caucus %>% 
  drop_na(twitter_handle)

cdi_2010_updated2 <- cdi_2010_2 %>% mutate(
  `2018` = case_when(
    Pre_2018_party == "R" & winner_party_2018 == "R" ~ "R",
    Pre_2018_party == "D" & winner_party_2018 == "D" ~ "D",
    Pre_2018_party == "R" & winner_party_2018 == "D" ~ "D+1",
    Pre_2018_party == "D" & winner_party_2018 == "R" ~ "D-1"))

CDI <- cdi_2010_updated2 %>% 
  select(CD, Cluster, `2018`)

Dem_caucus_CDI <- left_join(Dem_caucus2, CDI)

#Merge with tweet dataset 
Merged_Democrat_tweets_2023 <- full_join(Dem_caucus_CDI, Democrats_congress, by = c("twitter_handle" = "user_username") )



#BIND TO EARLIER TWEET DATASET 
Merged_Democrat_tweets1 <- Merged_Democrat_tweets %>% 
  select(-source) %>% 
  filter(Name != "Biden, Joe")
  
D_tweets_14_17_full <- rbind(Merged_Democrat_tweets1, Merged_Democrat_tweets_2023)




#Vice presidential tweets
#Biden VP 
Biden_VP <- get_all_tweets(
  users = c("JoeBiden", "VP44"),
  start_tweets = "2015-01-03T00:00:00Z",
  end_tweets = "2017-01-20T00:00:00Z",
  n = 100000, 
  data_path = "BVPtweetdata", 
  bind_tweets = FALSE)

Biden_VP <- Biden_VP %>%  bind_tweets(data_path = "BVPtweetdata", output_format = "tidy")

#Harris VP 
Harris_VP <- get_all_tweets(
  users = c("KamalaHarris", "VP"),
  start_tweets = "2021-01-20T00:00:01Z",
  end_tweets = "2023-01-03T00:00:00Z",
  n = 100000, 
  data_path = "HVP_data_2", 
  bind_tweets = FALSE)

Harris_VP <- Harris_VP %>%  bind_tweets(data_path = "HVP_data-2", output_format = "tidy")

#VP tweet merging 
Biden_VP1 <- Biden_VP %>% 
  select(-source)

VP <- rbind(Biden_VP1, Harris_VP)

#Dates 
date_updated <- str_sub(VP$created_at, 1, 10)

VP$created_at <- paste0(date_updated)

VP$created_at <- ymd(VP$created_at)

VP_congress <- VP %>% 
  mutate(congress = case_when(
    created_at >= ymd('2015-01-03') & 
      created_at <= ymd('2017-01-02') ~ "114",
    created_at >= ymd('2017-01-03') & 
      created_at <= ymd('2019-01-02') ~ "115",
    created_at >= ymd('2019-01-03') & 
      created_at <= ymd('2021-01-02') ~ "116",
    created_at >= ymd('2021-01-03') & 
      created_at <= ymd('2022-07-14') ~ "117"))

#Democratic caucus membership/district info 
official_handle <- read_excel("Yale/Amelia work/Uncleaned data/official_handle.xlsx")
cdi_2010_2 <- read_excel("Yale/Amelia work/Uncleaned data/cdi_2010_2.xlsx")

Dem_caucus <- pivot_longer(official_handle, 
                           cols = c(official_twitter, personal_twitter, third_twitter), 
                           names_to = "twitter_type", values_to = "twitter_handle")

Dem_caucus2 <- Dem_caucus %>% 
  drop_na(twitter_handle)

cdi_2010_updated2 <- cdi_2010_2 %>% mutate(
  `2018` = case_when(
    Pre_2018_party == "R" & winner_party_2018 == "R" ~ "R",
    Pre_2018_party == "D" & winner_party_2018 == "D" ~ "D",
    Pre_2018_party == "R" & winner_party_2018 == "D" ~ "D+1",
    Pre_2018_party == "D" & winner_party_2018 == "R" ~ "D-1"))

CDI <- cdi_2010_updated2 %>% 
  select(CD, Cluster, `2018`)

Dem_caucus_CDI <- left_join(Dem_caucus2, CDI)

#Merge with tweet dataset 
Merged_VP_tweets <- full_join(Dem_caucus_CDI, VP_congress, by = c("twitter_handle" = "user_username") )

#Mutate and merge with all other Democratic tweets 
Merged_VP_tweets1 <- Merged_VP_tweets %>% 
  mutate(VP = 1)

D_tweets_14_17_full1 <- D_tweets_14_17_full %>% 
  mutate(VP = 0)

D_tweets_full_VP <- rbind(Merged_VP_tweets1, D_tweets_14_17_full1)


#save tweets 
save(D_tweets_14_17_full, D_tweets_full_VP, file = "D_tweets_14_17_and_VP.Rdata")



#load tweets
load("/Users/ameliamalpas/Dropbox/Yale/Amelia work/R data/D_tweets_14_17_full.RData")


#CALCULATE TOP TRIGRAMS FOR EACH GROUP OF DEMOCRATS 
#All Dems
All_Democrats3 <- term_stats(D_tweets_14_17_full, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(All_Democrats3)

#Leadership 
Leadership <- D_tweets_14_17_full %>% 
  filter(Leadership == "1")

Leadership_3 <- term_stats(Leadership, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 0, ngrams = 3, types = TRUE)
View(Leadership_3)

#Progressive Caucus 
Progressive_Caucus <- D_tweets_14_17_full %>% 
  filter(`Congressional Progressive Caucus` == "1")

Progressive_Caucus3 <- term_stats(Progressive_Caucus, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(Progressive_Caucus3)

#Wealthy districts
Wealthy_districts <- D_tweets_14_17_full %>%
  filter(`Wealthy district` == "1")

Wealthy_districts3<- term_stats(Wealthy_districts, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(Wealthy_districts3)

#Poor districts 
Poor_districts <- D_tweets_14_17_full %>%
  filter(`Poor district` == "1")

Poor_districts3<- term_stats(Poor_districts, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(Poor_districts3)

#Suburban districts 
Suburban <- D_tweets_14_17_full %>%
  filter(Cluster == "Dense suburban" | Cluster == "Sparse suburban")

Suburban3<- term_stats(Suburban, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(Suburban3)

#Flipped districts 
Flipped <- D_tweets_14_17_full %>%
  filter(`2018` == "D+1")

Flipped3 <- term_stats(Flipped, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 3, types = TRUE)
View(Flipped3)



#Save all trigrams 

save(All_Democrats3, Leadership_3, Progressive_Caucus3, Flipped3, Suburban3, Wealthy_districts3, Poor_districts3, file = "Dem_trigrams_Jan_23.Rdata")





#REMOVE MEANINGLESS PHRASES 

`%!in%` <- Negate(`%in%`) #custom operator

#Trigrams to remove bc not substantive 
remove <- c('read full statement', 'years ago today', 'president united states', 'americans across country', 'tune deliver remarks', 
            'speaker nancy pelosi', 'live u.s capitol', 'vice president harris', 'american people deserve', 'join campaign today', 
            'united states capitol', 'long past time', 'live president obama', 'weekly press conference', 'add name agree', 
            'senate majority leader', 'president biden can', 'announced running president', 'just announced running', 
            'biden vice president', 'president biden vice', 'first 100 days', 'congress must act', 'every single day', 
            'today great day', 'new york across', 'people across country', 'breaking news kamala', 'get started join', 
            'help get started', 'kamala just announced', 'needs help get', 'news kamala just', 'president needs help', 
            'running president needs', 'started join campaign', '10 45 et', 'today every day', 'watch president obama', 
            'day president biden', 'great day president', 'communities across country', 'look forward serving', 'must act now', 
            'forward serving np', 'look forward working', 'president obama speaking', 'sign petition agree', 'vice president biden', 
            'now 202 224-3121', 'since took office', 'one year ago', 'senator mitch mcconnell', 'new york city', 'et watch president', 
            'call senator now', 'care call senator', 'join live u.s', 'sen chuck schumer', 'senator now 202', 'tax deduction average', 
            'took state local', 'house speaker nancy', 'weekly address president', 'america around world', 'take executive action', 
            'congratulations u.s representative-elect', 'speaking reporters live', 'telephone town hall', 'congressional art competition', 
            'make voice heard', 'today last day', 'one step closer', 'house just passed', 'congress must pass', 'proud join colleagues', 
            'virtual town hall', 'must held accountable', 'year ago today', 'look forward continuing', 'senate must pass', 
            'happy birthday friend', 'mobile office hours', 'need make sure', 'must work together', 'can work together', 
            'must take action', 'make voices heard', 'look forward seeing', 'must continue fight', 'two years ago', 
            'congressional app challenge', 'act signed law', 'happy new year', 'looking forward working', 'town hall meeting', 
            'health care providers', 'get things done', 'step right direction', 'forward continuing work', 'wishing happy birthday', 
            'today house passed', 'spoke house floor', 'make sure every', 'united states america', 'since house passed', 'looking forward joining', 
            'can count stand', 'count stand snap', 'can count support', 'know important public', 'families across country', 'house judiciary committee', 
            'right say stupid', 'birthday friend thank', 'house passed bill', 'house passed bipartisan', 'sheila jackson lee', 
            'congressional black caucus', 'congresswoman sheila jackson', 'house democrats passed', 'state reported today', 'days since girls', 
            'reported today cumulative', 'western new york', 'congresswoman brenda lawrence', 'rep lloyd doggett', 'u.s house representatives', 
            'congressional gold medal', 'congressman john lewis', 'join us tomorrow', 'cents every dollar', 'please join us', '50 years ago', 
            'family loved ones', 'members congress courage', "happy mother's day", 'act passed house', 'must come together', 'great see many', 
            'looking forward seeing', 'protect right vote', 'senate must act', 'help us fight', 'high school students', 'us fight back', 
            'rep maxine waters', 'never stop fighting', 'arpaio alex jones', 'joe arpaio alex', 'opponent using lies', 'pac roger stone', 
            'protrump pac roger', 'roger stone joe', 'stone joe arpaio', 'using lies forged', 'alex jones working', 'fight back donate', 
            'jones working w', 'w opponent using', 'working w opponent', 'please help us', 'afraid attack rep', 'attack rep maxine', 
            'directly protrump pac', 'documents dirty tricks', 'forged documents dirty', 'maxine waters directly', 'rep tulsi gabbard', 
            'lies forged documents', 'waters directly protrump', 'back donate campaign', 'dirty tricks please', 'tricks please help', 
            'colleagues sides aisle', 'upstate new york', 'working around clock', 'working make sure', 'town hall tomorrow', 'orange county families',
            'office 315 732-0713', 'thank everyone came', 'across united states', 'first town hall', 'lost loved ones', 'rep mike levin', 
            'week house passed', 'make sure get', 'burlington ocean counties', 'next town hall', 'make sure everyone', 'town hall tonight', 
            'need help federal', 'office can help', 'want make sure', 'across finish line', 'thank everyone joined', 'holding mobile office', 
            'help federal agency', 'working across aisle', 'forward working together', 'democrats stop fighting', 'may rest peace', 
            'let us remember', 'president trump still', 'trump still adequate', 'need bolster cut', 'program need bolster', 'trump afraid attack', 
            'one top priorities', 'problem solvers caucus', 'families across america', 'town hall last', 'work every day', 
            'democratic victory congratulations', 'york across country', 'capitol weekly press')


#Remove meaningless terms and select top 100 

#Leadership 
Leadership_clean <- Leadership_3 %>% filter(term %!in% remove)
Leadership_100 <- Leadership_clean[1:100, ]
Leadership_100 <- mutate(Leadership_100, "Group" = "Leadership")

View(All_100)

#All Democrats
All_clean <- All_Democrats3 %>% filter(term %!in% remove)
All_100 <- All_clean[1:100, ]
All_100 <- mutate(All_100, "Group" = "All Democrats")

#Wealthy 
Wealthy_clean <- Wealthy_districts3 %>% filter(term %!in% remove)
Wealthy_100 <- Wealthy_clean[1:100, ]
Wealthy_100 <- mutate(Wealthy_100, "Group" = "Wealthy districts")

#Poor 
Poor_clean <- Poor_districts3 %>% filter(term %!in% remove)
Poor_100 <- Poor_clean[1:100, ]
Poor_100 <- mutate(Poor_100, "Group" = "Poor districts")

#Suburban 
Suburban_clean <- Suburban3 %>% filter(term %!in% remove)
Suburban_100 <- Suburban_clean[1:100, ]
Suburban_100 <- mutate(Suburban_100, "Group" = "Suburban districts")

#Progressive  
Progressive_clean <- Progressive_Caucus3 %>% filter(term %!in% remove)
Progressive_100 <- Progressive_clean[1:100, ]
Progressive_100 <- mutate(Progressive_100, "Group" = "Progressives")

#Flipped seats 
Flipped_clean <- Flipped3 %>% filter(term %!in% remove)
Flipped_100 <- Flipped_clean[1:100, ]
Flipped_100 <- mutate(Flipped_100, "Group" = "Flipped districts")


#BIND DFs TOGETHER 
Dems_100 <- list(Leadership_100, All_100, Poor_100, Wealthy_100, Suburban_100, Progressive_100, Flipped_100) %>% 
  reduce(full_join, by = c("term", "Group", "count"))


#Save top 100 clean terms 
save(All_100, Leadership_100, Suburban_100, Wealthy_100, Poor_100, Progressive_100, Flipped_100, Dems_100, file = "Top_100_Jan_23.Rdata")






#Code contents of trigrams 

#Specific coding 
econ_programs_bills <- c("child tax credit", "student loan debt", "build back better", "american rescue plan",  
                         "back better agenda","bipartisan infrastructure law", "bipartisan infrastructure deal", "american jobs plan",
                         "medicaid social security", "medicare medicaid social", "back better act", "inflation reduction act", 
                         "social security medicare", "bold covid relief", "pass build back", "bipartisan infrastructure bill", "green new deal",
                         "infrastructure investment jobs", "investment jobs act", "paycheck protection program", "paid family leave",
                         "affordable child care", "family medical leave",  "safety net program","cancel student debt", "key safety net", 
                         "net program need",  "snap key safety", "stand snap key", "count stand snap", "paid family medical", 
                         "paid sick leave", "chips science act", "medicare social security")

econ_other <- c("middle class families","level playing field", "america's working families",  "good-paying union jobs", "pay fair share",
                "make ends meet", "state local tax","local tax deduction", "create millions good-paying", 
                "create good-paying jobs",  "millions good-paying jobs", "federal minimum wage", "deduction average deduction", "tax deduction average", 
                "took state local", "put food table", "15 minimum wage", "help small businesses",  "get back work",
                "public school funding", "school funding students", "funding students can", "families small businesses",
                "small business owners", "minimum wage 15", "raise minimum wage", "raising minimum wage", 
                "economic impact payments", "small businesses need", "million new jobs", "economic impact payment", 
                "support small businesses", "economy bottom middle", "corporations pay fair")

healthcare <- c("affordable care act", "medicaid social security", "medicare medicaid social",  "social security medicare","health care right", "people pre-existing conditions", "pre-existing condition protections", 
                "protections pre-existing conditions","protections americans pre-existing", "americans pre-existing conditions", 
                "affordable health care", "health care millions", "health care system", "away health care", "americans health care",
                "health care bill", "prescription drug prices", "health care costs", "access health care", "health care plan",
                "quality affordable health", "prescription drug costs",  "health care coverage",
                "losing health care", "health care call", "risk losing health",  "health protection act",  "community health centers", "health care workers", 
                "quality health care", "mental health care", "access quality affordable", "lower prescription drug", "make health care",
                "cost prescription drugs", "mental health services", "health care providers",  "lower health care","special enrollment period", 
                "care human right", "health care human", "lower drug costs", "mental health resources", "health care professionals",
                "health care providers", "health care away", "take away health", "health care workers", "health care need") 

econ_race_gender <- c("racial wealth gap", "close racial wealth",  "reproductive health care", 
                      "help close racial", "black maternal health", "equal pay equal", "pay equal work", "paycheck fairness act", 
                      "clean drinking water")

covid <- c("national testing strategy", "adequate national testing", "still adequate national", 
           "public health crisis", "public health emergency", "public health experts", "new covid-19 cases", "delayed test results", 
           "practice social distancing", "test results state", "results state reported", "help save lives", "health economic crisis", 
           "please stay safe")
climate <- c("fight climate change", "fight climate crisis", "combat climate change",  "fossil fuel industry", "great american outdoors", 
             "american outdoors act", "climate change real")
guns <- c("universal background checks", "gun violence prevention", "gun violence epidemic", "end gun violence", 
          "gun safety legislation", "background checks bill", "common sense gun", "prevent gun violence", 
          "bipartisan background checks", "background checks act", "assault weapons ban", "victims gun violence", "gun safety laws")
voting <- c("voting rights act", "lewis voting rights", "make plan vote", "voting rights advancement", "rights advancement act", 
            "r lewis voting","access ballot box", "john lewis voting", "john r lewis", "last day register", "find polling place",                  
            "days election day", "day register vote", "rights advancement act")

womens_rights <- c("roe v wade", "women's health protection", "violence women act", "equal rights amendment","woman's right choose")

cj_police <- c("criminal justice system", "end federal prohibition", "criminal justice reform", "federal prohibition marijuana",
               "justice policing act", "george floyd justice", "floyd justice policing")

black_history <- c("first black woman", "martin luther king", "luther king jr", "dr martin luther", "first african american", "civil rights movement",
                   "black history month")
culturally_conservative <- c("brave men women", "keep us safe", "keep communities safe", "made ultimate sacrifice",
                             "law enforcement officers", "put lives line", "men women uniform", "served active duty",  
                             "military defend right", "defend right say", "gold star families", 
                             "united states military",  "active duty united", "duty united states", "armed services committee",
                             "states military defend", "local law enforcement")
immigration <- c("dream promise act")

supreme_court <- c("nomination supreme court",  "kavanaugh's nomination supreme", 
                   "ketanji brown jackson", "brett kavanaugh's nomination", "judge ketanji brown", 
                   "supreme court justice", "supreme court nominee", "court united states", "supreme court united")

other <- c( "state local governments", "world war ii", "free open internet", "high school students",
            "since girls kidnapped",  "educator know important", "former educator know", "students can count", "important public school", 
            "rights human rights", "defense production act", "restaurant revitalization fund", "cut red tape", "end filibuster pass")


#Coding categories applied 
Dems_coded_nuanced <- 
  mutate(Dems_100, "Code" = case_when(term %in% econ_programs_bills ~ "economic programs & bills", 
                                      term %in% econ_other ~ "other directly economic", 
                                      term %in% healthcare ~ "health care", 
                                      term %in% econ_race_gender ~ "race & gender, directly material", 
                                      term %in% womens_rights ~ "women's rights", 
                                      term %in% covid ~ "Covid-19", 
                                      term %in% climate ~ "climate change", 
                                      term %in% guns ~ "gun violence", 
                                      term %in% voting ~ "voting rights", 
                                      term %in% c(cj_police, black_history, immigration) ~ "Black & Hispanic rights", 
                                      term %in% culturally_conservative ~ "conservative heroes: cops & military", 
                                      term %in% supreme_court ~ "Supreme Court",
                                      term %in% other ~ "other")) 

Dems_coded_broad <- mutate(Dems_coded_nuanced, 
                           "Broad_code" = case_when(Code %in% c("Black & Hispanic rights", "women's rights") ~ "rights, race & gender", 
                                                    Code %in% c("conservative heroes: cops & military") ~ "conservative heroes", 
                                                    Code %in% c("economic programs & bills","other directly economic") ~ "economic", 
                                                    Code %in% c("health care") ~ "health care", 
                                                    Code %in% c("other") ~ "other", 
                                                    Code %in% c("race & gender, directly material") ~ "material, race & gender",
                                                    Code %in% c("gun violence") ~ "gun violence", 
                                                    Code %in% c("climate change") ~ "climate change",
                                                    Code %in% c("Covid-19") ~ "Covid-19 pandemic",
                                                    Code %in% c("voting rights") ~ "voting rights", 
                                                    Code %in% c("Supreme Court") ~ "Supreme Court"))
View(Dems_coded_broad)

#stats on coded terms 
stats <- Dems_coded_broad %>% 
  group_by(Group, Broad_code) %>% 
  dplyr::summarize(Number = n(), Weight = sum(count))

broad_stats <- stats %>% 
  filter(Group == "All Democrats") %>% 
  select(Broad_code, Number) %>% 
  rename("All_Dems" = Number)

stats <- left_join(stats, broad_stats, by="Broad_code") 
stats$Group <- factor(stats$Group.x, levels = c("All Democrats", "Leadership", "Poor districts", "Progressives",
                                                "Flipped districts", "Suburban districts", "Wealthy districts"))



#Plot makeup of top coded terms 
col <- brewer.pal(9, "Blues")
col <- colorRampPalette(col)(11)


stats <- stats %>%
  mutate(Broad_code = fct_reorder(Broad_code, desc(All_Dems)))



stats <- tweet_topic 

#original figure 

ggplot(stats, aes(x = Group, y = Number, fill = Broad_code)) +
  scale_fill_viridis_d(begin = "0.2", end = "1", option = "G") + 
  geom_col(position = "dodge") + theme_classic() + labs(x = "Group", y = "Percent", fill = "Topic")

ggsave("Twitter topics.png", height = 8, width = 12)



#Save coded terms and their stats 
save(Dems_coded_broad, stats, file = "Tweet_topic.Rdata")

Dems_coded_broad <- Dems_coded_broad[, -c(8:31)]

write.csv(stats, file = "tweet_topic.csv")






#BIGRAMS & QUADRIGRAMS 


All_Democrats2 <- term_stats(D_tweets_14_17_full, 
                             text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), 
                                         drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(All_Democrats2)

All_Democrats4 <- term_stats(D_tweets_14_17_full, 
                             text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), 
                                         drop_punct = TRUE), min_count = 5, ngrams = 4, types = TRUE)
View(All_Democrats4)

#Leadership 
Leadership <- D_tweets_14_17_full %>% 
  filter(Leadership == "1")

Leadership_2 <- term_stats(Leadership, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Leadership_2)

Leadership_4 <- term_stats(Leadership, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 4, types = TRUE)
View(Leadership_4)

#Progressive Caucus 
Progressive_Caucus <- D_tweets_14_17_full %>% 
  filter(`Congressional Progressive Caucus` == "1")

Progressive_Caucus2 <- term_stats(Progressive_Caucus, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Progressive_Caucus2)

#Wealthy districts
Wealthy_districts <- D_tweets_14_17_full %>%
  filter(`Wealthy district` == "1")

Wealthy_districts2<- term_stats(Wealthy_districts, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Wealthy_districts2)

#Poor districts 
Poor_districts <- D_tweets_14_17_full %>%
  filter(`Poor district` == "1")

Poor_districts2<- term_stats(Poor_districts, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Poor_districts2)

#Suburban districts 
Suburban <- D_tweets_14_17_full %>%
  filter(Cluster == "Dense suburban" | Cluster == "Sparse suburban")

Suburban2<- term_stats(Suburban, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Suburban2)

#Flipped districts 
Flipped <- D_tweets_14_17_full %>%
  filter(`2018` == "D+1")

Flipped2 <- term_stats(Flipped, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), min_count = 5, ngrams = 2, types = TRUE)
View(Flipped2)







#Republican leadership 
load("/Users/ameliamalpas/Dropbox/Yale/Amelia work/R data/Partyleaders.Rdata")

GOP <- Partyleaders %>% 
  filter(party == "Republican")

GOP_2 <- term_stats(GOP, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  
                                     drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), 
                    min_count = 5, ngrams = 2, types = TRUE)
View(GOP_2)

GOP_4 <- term_stats(GOP, text_filter(drop_symbol = TRUE, stem_dropped = TRUE,  
                                     drop = c(stopwords_en, "rt", "amp"), drop_punct = TRUE), 
                    min_count = 5, ngrams = 4, types = TRUE)
View(GOP_4)







